package com.example.concurrent.chapter09;

import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @author Create By Liuqz
 * @date 2018/11/23 14:42
 */
public class ClassInit {

    //静态语句块只能对后面的静态变量进行赋值,但是不能对其进行访问
    /*static {
        x=100;
        System.out.println(x);
    }

    private static int x = 10;*/

    /*
    //父类中有静态变量value
    static class Parent{
        static int value = 10;

        static {
            value = 20;
        }
    }

    static class Child extends Parent {
        static int i = value;
    }

    public static void main(String[] args) {
        *//**
         * 输出结果为 20
         * 父类的静态变量总是能够得到优先赋值
         *//*
        System.out.println(Child.i);
    }*/


    static {
        try {
            System.out.println("The ClassInit static code block will be invoke.");
            TimeUnit.MINUTES.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        IntStream.range(0,5).forEach(i -> new Thread(ClassInit::new));
    }
}
